﻿using System.Threading.Tasks;
using Volo.Abp.Identity.Localization;
using Volo.Abp.UI.Navigation;

namespace Volo.Abp.Identity.Blazor
{
    public class AbpIdentityWebMainMenuContributor : IMenuContributor
    {
        public virtual Task ConfigureMenuAsync(MenuConfigurationContext context)
        {
            if (context.Menu.Name != StandardMenus.Main)
            {
                return Task.CompletedTask;
            }

            var administrationMenu = context.Menu.GetAdministration();

            var l = context.GetLocalizer<IdentityResource>();

            var identityMenuItem = new ApplicationMenuItem(IdentityMenuNames.GroupName, l["Menu:IdentityManagement"],
                icon: "far fa-id-card");
            administrationMenu.AddItem(identityMenuItem);

            identityMenuItem.AddItem(new ApplicationMenuItem(
                    IdentityMenuNames.Roles,
                    l["Roles"],
                    url: "~/identity/roles",
                    requiredPermissionName: IdentityPermissions.Roles.Default));


            identityMenuItem.AddItem(new ApplicationMenuItem(
                IdentityMenuNames.Users,
                l["Users"],
                url: "~/identity/users",
                requiredPermissionName: IdentityPermissions.Users.Default));

            return Task.CompletedTask;
        }
    }
}
